package com.ljq.rpc.client.utils;

import com.ljq.rpc.annotations.ProxyScan;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.annotation.AnnotationAttributes;
import org.springframework.core.type.AnnotationMetadata;

public class AutoMapperScanImportBeanDefinitionRegistrar implements ImportBeanDefinitionRegistrar {
    @Override
    public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
        // 获取MapperScan注解属性信息
        AnnotationAttributes annotationAttributes = AnnotationAttributes.fromMap(importingClassMetadata.getAnnotationAttributes(ProxyScan.class.getName()));
        // 获取注解的属性值,拿到定义的扫描路径
        String[] basePackages = annotationAttributes.getStringArray("basePackage");
        // 使用自定义扫描器扫描
        AutoMapperScanClassPathBeanDefinitionScanner scanner = new AutoMapperScanClassPathBeanDefinitionScanner(registry, false);
        scanner.doScan(basePackages);
    }
}
